<?php
namespace app\forum\controller;
use app\forum\controller\UserController;
/**
 * 帖子管理
 */
class ThreadController extends UserController {

    /**
     * 管理
     */
    public function manage(){
        $threadId = request('request.thread_id',0,'intval');
        if (empty($threadId)) {
            $this->error404();
        }
        $threadInfo = target('forum/Thread')->getInfo($threadId);
        //信息判断
        if(empty($threadInfo)){
            $this->error404();
        }
        //获取板块信息
        $plateInfo = target('forum/Plate')->getInfo($threadInfo['plate_id']);
        //判断管理权限
        $manage = explode(',', $plateInfo['manage']);
        if(!$this->loginUserInfo['admin'] && !in_array($this->loginUserInfo['username'], $manage)){
            $this->error('您没有权限管理本帖！');
        }
        if(!IS_POST){
            //位置导航
            $crumb = target('forum/Plate')->loadCrumb($threadInfo['plate_id']);
            $this->crumb = array_merge($this->crumb,$crumb);
            $this->crumb[] = array('url'=>url('posts/Push/edit',array('thread_id'=>$threadId)), 'name'=>'帖子管理');
            $this->assign('info',$threadInfo);
            $this->siteDisplay('index');
        }else{
            $data = request('post.');
            if(target('forum/Thread')->editData($data)){
                $this->success('帖子设置成功！',url($threadInfo['app'].'/Thread/index',array('thread_id'=>$threadId)));
            }else{
                $msg = target('forum/Thread')->getError();
                if(empty($msg)){
                    $this->error('帖子设置失败');
                }else{
                    $this->error($msg);
                }
            }
        }
    }

}

